package lib

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"path/filepath"
)

var (
	Basedir = "../chinaz_jiaoben/"
)

func Downlaod(url, filename string) {
	name := filepath.Base(url)
	if !Check_file(Basedir + filename + "/" + filename + name) {
		res, err := http.Get(url)
		if err != nil {
			fmt.Printf("HTTP ERROR:%s", err)
			return
		}
		defer res.Body.Close()

		files, err := os.Create(Basedir + filename + "/" + filename + name)
		if err != nil {
			fmt.Printf("File ERROR:%s", err)
			return
		}
		io.Copy(files, res.Body)

		fmt.Println(filename + " is download!")
	} else {
		fmt.Println(Basedir + filename + "/" + filename + name + "  has exsit")
	}

}
